/**
 * This class creates bezier tween functions.
 * 
 * @author back2dos
 */
class Bezier {
	static private function fac(n:Number) {
		return n ? n * fac(n - 1) : 1;
	}
	static private function bernstein(x:Number, i:Number, n:Number) {
		var c:Number = fac(n) / fac(i) / fac(n - i);
		return function (t:Number):Number {
			return x * c * Math.pow(t, i) * Math.pow(1 - t, n - i);
		}
	}
	public static function make(values:Array):Function {
		for (var i:Number = 0; i < values.length; i++) 
			values[i] = bernstein(values[i], i, values.length - 1);
		return function (progress:Number):Number {
			var ret:Number = 0;
			for (var i:Number = 0; i < values.length; i++)
				ret += values[i](progress);
			return ret;
		}
	}
}